package net.tv90.volunteerserveradmin.dao;

import io.lettuce.core.dynamic.annotation.Param;
import net.tv90.volunteerserveradmin.model.domain.Image;
import net.tv90.volunteerserveradmin.model.domain.ProjectTeacherRelation;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ProjectTeacherRelationRepository extends JpaRepository<ProjectTeacherRelation, Long>, JpaSpecificationExecutor<ProjectTeacherRelation> {
    // 检查教师是否已负责该项目
    @Query("SELECT COUNT(*) > 0 FROM ProjectTeacherRelation WHERE teacherId = :teacherId AND projectId = :projectId\n")
    boolean existsByTeacherIdAndProjectId(Long teacherId, Long projectId);

    // 根据教师ID和项目ID查询关系
    ProjectTeacherRelation findByTeacherIdAndProjectId(Long teacherId, Long projectId);

    // 根据教师ID查询所有的项目关系
    List<ProjectTeacherRelation> findByTeacherId(Long teacherId);

    @Query("SELECT p.teacherId FROM ProjectTeacherRelation p WHERE p.projectId = :projectId")
    List<Long> findTeacherIdsByProjectId(@Param("projectId") Long projectId);

    Long countByProjectId(Long projectId);

    @Query("SELECT p.projectId FROM ProjectTeacherRelation p WHERE p.teacherId = :teacherId")
    List<Long> findProjectIdsByTeacherId(Long teacherId);

}